package com.zemb.flxwear.PERMISSION;

import android.app.Activity;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;

//单例模式
public class PermissionUtils {
    private static PermissionUtils instance;
    public static PermissionUtils getInstance() {
        return instance;
    }
    public PermissionUtils() {
        instance = this;
    }
    public static final int REQUEST_CODE = 0; // 请求码
    public static String[] PERMISSIONS_STORAGE = {
            "android.permission.READ_EXTERNAL_STORAGE",
            "android.permission.WRITE_EXTERNAL_STORAGE"
    };
    public static String[] PERMISSIONS_LOCATION = {
            "android.permission.ACCESS_FINE_LOCATION",
            "android.permission.ACCESS_COARSE_LOCATION"
    };
    public static String[] PERMISSIONS_CONTACTS = {
            "android.permission.READ_CONTACTS",
            "android.permission.WRITE_CONTACTS",
            "android.permission.GET_ACCOUNTS"
    };
    public static String[] PERMISSIONS_CALENDAR = {
            "android.permission.READ_CALENDAR",
            "android.permission.WRITE_CALENDAR"
    };
    public static String[] PERMISSIONS_CAMERA = {
            "android.permission.CAMERA"
    };
    public static String[] PERMISSIONS_MICROPHONE = {
            "android.permission.RECORD_AUDIO"
    };
    public static String[] PERMISSIONS_PHONE = {
            "android.permission.READ_PHONE_STATE",
            "android.permission.CALL_PHONE",
            "android.permission.READ_CALL_LOG",
            "android.permission.WRITE_CALL_LOG",
            "com.android.voicemail.permission.ADD_VOICEMAIL",
            "android.permission.USE_SIP",
            "android.permission.PROCESS_OUTGOING_CALLS"
    };
    public static String[] PERMISSIONS_SENSORS = {
            "android.permission.BODY_SENSORS"
    };
    public static String[] PERMISSIONS_SMS = {
            "android.permission.SEND_SMS",
            "android.permission.RECEIVE_SMS",
            "android.permission.READ_SMS",
            "android.permission.RECEIVE_WAP_PUSH",
            "android.permission.RECEIVE_MMS"
    };
    //BLE蓝牙权限
        public static String[] PERMISSIONS_BLUETOOTH = {
                "android.permission.BLUETOOTH",
                "android.permission.BLUETOOTH_ADMIN",
            "android.permission.ACCESS_FINE_LOCATION",
            "android.permission.ACCESS_COARSE_LOCATION",
        };


    // 验证并申请权限
    public static void verifyStoragePermissions(String permission, Activity activity) {
        // Check if we have write permission
        int state = ActivityCompat.checkSelfPermission(activity, permission);
        if (state != PackageManager.PERMISSION_GRANTED) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(
                    activity,
                    PERMISSIONS_STORAGE,
                    REQUEST_CODE
            );
        }
    }
    // 回调函数
    public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // Permission Granted
                } else {
                    // Permission Denied
                }
                break;
        }
    }


    

    
}
